package com.hzhk.happyrent.network;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.widget.Toast;

import com.hzhk.happyrent.ui.dialog.LoadingDialog;
import com.tamic.novate.callback.RxStringCallback;
import com.tamic.novate.util.NetworkUtil;

/**
 * User: hzhk(1097282555@qq.com)
 * Date: 2017/11/28
 * Time: 14:24
 * progject: hzk
 * Describe： ${Describe}
 */
public abstract class MyStringResponse extends RxStringCallback {

    private Dialog dialog;
    private Context context;

    public MyStringResponse(Context context) {
        this.context = context;
        dialog=new LoadingDialog((Activity) context,"");

    }
    @Override
    public void onStart(Object tag) {
        super.onStart(tag);
        if (!NetworkUtil.isNetworkAvailable(context)) {
            Toast.makeText( context, "网络异常",Toast.LENGTH_SHORT).show();
            onCompleted(tag);
            return;
        }
        if(dialog!=null){
            if(dialog.isShowing()){
                dialog.dismiss();
            }
            dialog.show();
        }
    }


    @Override
    public void onCompleted(Object tag) {
        super.onCompleted(tag);
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

}
